/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.icanci.tomato.config;

import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
 * 接口文档 - swaggerui 只有dev环境才会生效
 *
 * 访问地址：http://ip:port/swagger-ui.html
 *
 * @author icanci
 * @date Created in 2021/04/10 22:52
 * @version 1.0
 */
@Profile("dev")
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    public static final String CONTACT_NAME          = "icanci";
    public static final String CONTACT_URL           = "https://icanci.oschina.io/";
    public static final String CONTACT_EMAIL         = "icanci@foxmail.com";

    public static final String API_INFO_TITLE        = "Tomato Service API";
    public static final String API_INFO_DESC         = "Tomato 是一个Web[App]软件，用来记录自己的生活、待办四象限、番茄工作法、日历、每日一谋、完成与统计等等功能。成为更好的自己~";
    public static final String API_INFO_VERSION      = "v1.0";
    public static final String API_INFO_URL          = "https://icanci.oschina.io/";
    public static final String API_INFO_LICENSE_NAME = "Apache 2.0";
    public static final String API_INFO_LICENSE_URL  = "http://www.apache.org/licenses/LICENSE-2.0";

    /**
     * 配置Swagger的bean实例
     *
     * @return 返回 Docket 对象
     */
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());
    }

    /**
     * 配置Swagger信息  = apiInfo
     *
     * @return 返回 ApiInfo 对象
     */
    @Bean
    public ApiInfo apiInfo() {
        Contact contact = new Contact(CONTACT_NAME, CONTACT_URL, CONTACT_EMAIL);
        return new ApiInfo(API_INFO_TITLE, API_INFO_DESC, API_INFO_VERSION, API_INFO_URL, contact, API_INFO_LICENSE_NAME, API_INFO_LICENSE_URL, new ArrayList<VendorExtension>());
    }
}